#include<bits/stdc++.h>
using namespace std;
map<long long,int> m;
int n,a,b,c,d,e;
string s,s2;
char cc[105];
int len(int x)
{
	if(x==0)return 1;
	int ans=0;
	while(x)
	{
		ans++;
		x/=10;
	} 
	return ans;
} 
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>n;
	for(int T=1;T<=n;T++)
	{
		a=-1,b=-1,c=-1,d=-1,e=-1; 
		cin>>s;
		cin>>cc;
		sscanf(cc,"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e);
		if(a==-1||b==-1||c==-1||d==-1||e==-1)
		{
			cout<<"ERR"<<endl;
			continue;
		}
		if(a>255||b>255||c>255||d>255||e>65535)
		{
			cout<<"ERR"<<endl;
			continue;			
		}
		if(len(a)+len(b)+len(c)+len(d)+len(e)+4!=strlen(cc))
		{
			cout<<"ERR"<<endl;
			continue;			
		}
		long long sum=0;
		sum+=a;
		sum*=1000;
		sum+=b;
		sum*=1000;
		sum+=c;
		sum*=1000;
		sum+=d;
		sum*=100000;
		sum+=e;
		if(s=="Server")
		{
			if(m[-sum])
			{
				cout<<"FAIL"<<endl;
				continue; 
			}
			m[-sum]=T;
			cout<<"OK"<<endl;
		} 
		else
		{
			if(!m[-sum])
			{
				cout<<"FAIL"<<endl;
				continue; 
			}
			cout<<m[-sum]<<endl;		
		}
	}	
}
